import axios from '../../libs/request'

/**
 * @param { number } status 0 已发表
 * @param { number } status 1 已上传未发表
 * @param { number } status 2 已撤回
 */

/**
 * 搜索标题
 * @param {*} title 
 * @param {*} status 
 * @param {*} pageSize 
 */
export const searchTitle = (title, status, pageSize = 10) => axios.request({
  url: '/api/v1/admin/paper/title',
  method: 'get',
  params: {
    keyword: title,
    size: pageSize,
    status
  }
})
/**
 * 根据状态值获取所有已保存的论文
 * @param {*} status 
 * @param {*} pageIndex 
 * @param {*} pageSize 
 */
export const getAll = (status, pageIndex, pageSize = 10) => axios.request({
  url: '/api/v1/admin/paper',
  method: 'get',
  params: {
    from: pageIndex,
    size: pageSize,
    status
  }
})

/**
 * 上传论文
 * @param { array } papers 论文数组
 * [
  {
    "id": "string",
    "title": "string",
    "authers": [
      "string"
    ],
    "publishedTime": "2020-06-18T16:45:03.463Z",
    "keywords": [
      "string"
    ],
    "summary": "string",
    "modifyTime": "2020-06-18T16:45:03.463Z",
    "downloads": 0,
    "fileName": "string",
    "filePath": "string",
    "status": 0
  }
]
 */
export const put = papers => axios.request({
  url: '/api/v1/admin/paper',
  method: 'put',
  data: papers
})

/**
 * 修改论文
 * @param { object } paper 论文
 */
export const update = paper => axios.request({
  url: '/api/v1/admin/paper',
  method: 'post',
  data: paper
})

/**
 * 删除指定论文
 * @param { string [] } paperIdArray 论文ID数组
 */
export const deletes = paperIdArray => axios.request({
  url: '/api/v1/admin/paper',
  method: 'delete',
  data: paperIdArray
})

/**
 * 发表指定论文
 * @param { string [] } paperIdArray 论文ID数组
 */
export const publish = paperIdArray => axios.request({
  url: '/api/v1/admin/paper/publication',
  method: 'post',
  data: paperIdArray
})

/**
 * 撤回指定论文
 * @param { string [] } paperIdArray 论文ID数组
 */
export const revocation = paperIdArray => axios.request({
  url: '/api/v1/admin/paper/revocation',
  method: 'post',
  data: paperIdArray
})